<template>
	<div class="uploadpart my-flex-between">
		<input class="upfile" for="uploads" type="file" accept="image/png, image/jpeg, image/gif, image/jpg" @change="uploadImg($event)" />
		<img class="upimg" id="uploads" :src="obj.businessLicenseUrl?obj.businessLicenseUrl:defaulticon" />
	</div>
</template>
<script>
	import $ from 'jquery';
	export default {
		props: {
			obj:{
				type:Object,
				default:{}
			},
			
			retrunimg:{
				type:String,
				default:''
			},
			
			cutAreaShow:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaulticon:require('./upload.png'),
			}
		},
		mountd(){
			
		},
		methods: {
			
		uploadImg($event) {
				let that = this;
				let files = $event.target.files;
				for(let file of files) {
					//本地预览
					var oFReader = new FileReader();
					oFReader.readAsDataURL(file);
					oFReader.onload = function(oFREvent) {
						var s = oFREvent.target.result;
						var index = s.indexOf(',')
						var t = s.substring(index + 1, s.length)
						$($event.target).siblings('img').prop("src", s);
					};
					var filename = file.name
					var AllImgExt = ".jpg|.png|.jpeg|";
					var type = filename.substring(filename.lastIndexOf(".")).toLowerCase();
					var formData = new FormData();
					formData.append('file', file);
					this.httptool.ajaxFilePost('upload', formData, (res) => {
						if(res.code == 1) {
							this.obj.businessLicense = res.data.id;
							console.log(this.obj.businessLicense);
						}
					})
				}
 
		    },
			clearInputFile(f) { //清除fileinput
				if(f.value) {
					try {
						f.value = ''; //for IE11, latest Chrome/Firefox/Opera...
					} catch(err) {}
					if(f.value) { //for IE5 ~ IE10
						var form = document.createElement('form'),
							ref = f.nextSibling;
						form.appendChild(f);
						form.reset();
						ref.parentNode.insertBefore(f, ref);
					}
				}
			}
		}
	}
</script>
<style type="text/css" lang="less">
	/*@import '../../less/base/base.less';*/
	.uploadpart {
		position: relative;
		.upfile {
			position: absolute;
			left: 0;
			opacity: 0;
			height: 100px;
			width: 100px;
		}
		.upimg {
			width: 100px;
			height: 100px;
		}
	}
</style>